package com.xuxin.baby.model;

import com.xuxin.baby.base.BaseConstant;
import com.xuxin.baby.bean.BaseBean;
import com.xuxin.baby.bean.ChildSicknessBean;
import com.xuxin.baby.contract.ChildSicknessContract;
import com.xuxin.baby.network.Retrofit;
import com.xuxin.baby.network.RetrofitApi;
import com.xuxin.baby.network.myObserver;
import com.xuxin.baby.presenter.ChildSicknessPresenter;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.observers.DisposableObserver;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
 * Created by xu_xin
 * Created on 2020/10/22 0022
 * 看病记录
 */
public class ChildSicknessModel implements ChildSicknessContract.Model {
    @Override
    public void getChildSickness(ChildSicknessPresenter presenter,
                                 String tenantId,
                                 String token,
                                 String childId,
                                 String eventType,
                                 int skipCount,
                                 int maxCount) {
        if (maxCount == 0) {
            maxCount = BaseConstant.page_limit;
        }
        Retrofit.getInstance().createReq(RetrofitApi.class)
                .getChildSickness(tenantId, token,"1", childId, eventType, skipCount * BaseConstant.page_limit, maxCount)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new myObserver<ChildSicknessBean>() {
                    @Override
                    public void onNextX(@NonNull ChildSicknessBean childSicknessBean) {
                        if (childSicknessBean.isSuccess()) {
                            presenter.onSuccess(childSicknessBean);
                        } else {
                            presenter.onError(childSicknessBean);
                        }
                    }
                    @Override
                    public void onError(BaseBean baseBean) {
                        presenter.onError(baseBean);
                    }
                    @Override
                    public void onError(@NonNull Throwable e) {
                        presenter.onError(null);
                    }

                    @Override
                    public void onComplete() {
                        presenter.onComplete();
                    }
                });
    }
}